<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('update-history-all')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      v-for="(item, ind) in searchHistories"
      :key="ind"
      :title="item"
      @click="onSearchItemClick(item, ind)"
    >
      <van-icon v-if="isDeleteShow" name="close" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      typeof: Array,
      require: true
    }
  },
  data () {
    return {
      // searchHistories: [],
      isDeleteShow: false
    };
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onSearchItemClick (item, ind) {
      if (this.isDeleteShow) {
        // 删除数据
        this.searchHistories.splice(ind, 1);
      } else {
        // 搜索数据
        this.$emit('search', item);
      }
    }
  }
};
</script>

<style scoped lang="less"></style>
